﻿using System;
using System.Globalization;
using System.Windows.Data;

namespace CannedHeater.View.Converters
{
    /// <summary>
    /// Converts a timespan to a short string (only supports hours and days)
    /// </summary>
    public class TimeSpanConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value == null) return "";

            TimeSpan val = (TimeSpan)value;

            if (val == TimeSpan.Zero) return "";

            if (val.Days == 1) return "(24 hrs)";
            else if (val.Days != 0) return "(" + val.Days.ToString() + " days)";
            else if (val.Hours == 1 ) return "(1 hr)";
            else return "(" + val.Hours.ToString() + " hrs)";
            
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return null; // Not needed
        }
    }
}
